<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models\Projects;

use App\Models\TestApi\TestModule;
use Carbon\Carbon;
use App\Models\Eloquent;
use App\Models\Meimei\Traits\SignOssUrlTrait;
use App\Models\Meimei\Traits\ExplodeTrait;

/**
 * Class QtpProduct
 *
 * @property int $id
 * @property string $icon
 * @property int $cate_id
 * @property int $project_id
 * @property string $name
 * @property string $version
 * @property string $remark
 * @property string $note
 * @property string $tags
 * @property string $created_adminer
 * @property string $updated_adminer
 * @property int $sort
 * @property int $enable
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class Product extends Eloquent
{
    use ExplodeTrait;
    use SignOssUrlTrait;
    protected $explode_img = ['icon']; // 单图
    protected $explode = ['tags'];

	protected $table = 'products';

	protected $casts = [
		'cate_id' => 'int',
		'project_id' => 'int',
		'sort' => 'int',
		'enable' => 'int'
	];

	protected $fillable = [
		'icon',
		'cate_id',
		'project_id',
		'name',
		'version',
		'remark',
		'note',
		'tags',
		'created_adminer',
		'updated_adminer',
		'sort',
		'enable'
	];

    public function label()
    {
        $this->project_name = Project::find($this->project_id)->name ?? '';
        $this->cate_name = ProjectCate::find($this->cate_id)->name ?? '';
        $this->test_sum = TestModule::where('product_name', $this->name)->count();
        return $this;
    }

    public static $fillables = [
        'icon' => '产品图标',
        'cate_id' => '产品分类ID',
        'project_id' => '产品所属项目ID',
        'name' => '产品名称',
        'version' => '产品版本号',
        'remark' => '产品描述',
        'note' => '产品备注',
        'tags' => '产品标签',
        'created_adminer'  => '产品创建人',
        'updated_adminer'  => '产品更新人',
        'sort' => '产品排序',
        'enable' => '产品状态',
    ];
}
